﻿using ConsoleApp3;
using System.Collections.Generic;
using System.Data;
using System.Reflection.Metadata.Ecma335;
using System.Xml.Linq;
string absoluteFilePath = System.IO.Path.GetFullPath(args[0]);
string absoluteExcellPath = System.IO.Path.GetFullPath(args[1]);
if (!Directory.Exists(absoluteFilePath) || !Directory.Exists(absoluteExcellPath))
{
    throw new Exception("文件夹不存在");
}
var dir = Directory.CreateDirectory(absoluteFilePath);
var files = dir.GetFiles().Select(f => f.Name);

var dir2 = Directory.CreateDirectory(absoluteExcellPath);

var tables = dir2.GetFiles();

var dir3 = Directory.CreateDirectory("newfiles");
foreach (var file in dir2.GetFiles())
{
    Console.WriteLine($"开始处理:{file.Name}");
    var fullName = file.FullName;
    var name = Path.GetFileNameWithoutExtension(file.Name);
    var s = name.Split('-');
    var minId = decimal.Parse(s[0]);
    var maxId = decimal.Parse(s[1]);
    var curFiles = files.Where(f =>
    {
        if (decimal.TryParse(f, out var v))
        {
            return v >= minId && v <= maxId;
        }
        return false;
    });
    var com = new ExcellConnection(fullName);

    foreach (var item in curFiles)
    {
        await com.CopyFileAsync(args[0], item, dir3.FullName);
    }
    Console.WriteLine($"处理:{file.Name} 结束");

}
Console.WriteLine("Ok");




